//* ......................我佛慈悲......................
//*                       _oo0oo_
//*                      o8888888o
//*                      88" . "88
//*                      (| -_- |)
//*                      0\  =  /0
//*                    ___/`---'\___
//*                  .' \\|     |// '.
//*                 / \\|||  :  |||// \
//*                / _||||| -卍-|||||- \
//*               |   | \\\  -  /// |   |
//*               | \_|  ''\---/''  |_/ |
//*               \  .-\__  '-'  ___/-. /
//*             ___'. .'  /--.--\  `. .'___
//*          ."" '<  `.___\_<|>_/___.' >' "".
//*         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//*         \  \ `_.   \_ __\ /__ _/   .-` /  /
//*     =====`-.____`.___ \_____/___.-`___.-'=====
//*                       `=---='
//*
//*..................佛祖开光 ,永无BUG...................
//          佛曰:
//                  写字楼里写字间，写字间里程序员；
//                  程序人员写程序，又拿程序换酒钱。
//                  酒醒只在网上坐，酒醉还来网下眠；
//                  酒醉酒醒日复日，网上网下年复年。
//                  但愿老死电脑间，不愿鞠躬老板前；
//                  奔驰宝马贵者趣，公交自行程序员。
//                  别人笑我忒疯癫，我笑自己命太贱；
//                  不见满街漂亮妹，哪个归得程序员？
//
//  ViewModel.m
//  Cell
//
//  Created by WLJ on 21/10/2016.
//  Copyright © 2016 WLJ. All rights reserved.
//

#import "ViewModel.h"
#import "Model.h"
@interface ViewModel ()
@property(nonatomic,copy,readwrite)NSString * tip;
@property(nonatomic,copy,readwrite)NSString * headerUrl;
@property(nonatomic,copy,readwrite)NSString * name;
@property(nonatomic,copy,readwrite)NSString * classs;
@property(nonatomic,copy,readwrite)NSString * phone;
@property(nonatomic,copy,readwrite)NSString * physical;
@property(nonatomic,copy,readwrite)NSString * numb;
@end

@implementation ViewModel
+(instancetype)viewModelWithMode:(id)model{
    return ({Model * models = model;
            ViewModel * viewModel = [[ViewModel alloc]init];
            viewModel.tip = models.tip;
            viewModel.headerUrl = models.headerUrl;
            viewModel.name = models.name;
            viewModel.classs = models.classs;
            viewModel.phone = models.phone;
            viewModel.physical = models.physical;
            viewModel.numb = models.numb;
            viewModel;
        });
}


-(RACCommand *)btn0Command{
    return [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            ViewModel * viewModel = input;            
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@",viewModel.tip,viewModel.name,viewModel.classs,viewModel.physical,viewModel.phone,viewModel.numb] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"取消"];
                [subscriber sendCompleted];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"出错" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendError:[NSError errorWithDomain:@"出错！" code:-1 userInfo:nil]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"完成"];
                [subscriber sendCompleted];
            }]];
            [[[[[UIApplication sharedApplication]delegate]window]rootViewController] presentViewController:alert animated:YES completion:nil];
            return nil;
        }];
    }];
}
-(RACCommand *)btn1Command{
    return [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            ViewModel * viewModel = input;
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@",viewModel.tip,viewModel.name,viewModel.classs,viewModel.physical,viewModel.phone,viewModel.numb] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"取消"];
                [subscriber sendCompleted];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"出错" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendError:[NSError errorWithDomain:@"出错！" code:-1 userInfo:nil]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"完成"];
                [subscriber sendCompleted];
            }]];
            [[[[[UIApplication sharedApplication]delegate]window]rootViewController] presentViewController:alert animated:YES completion:nil];
            return nil;
        }];
    }];
}
-(RACCommand *)btn2Command{
    return [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            ViewModel * viewModel = input;
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@",viewModel.tip,viewModel.name,viewModel.classs,viewModel.physical,viewModel.phone,viewModel.numb] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"取消"];
                [subscriber sendCompleted];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"出错" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendError:[NSError errorWithDomain:@"出错！" code:-1 userInfo:nil]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"完成"];
                [subscriber sendCompleted];
            }]];
            [[[[[UIApplication sharedApplication]delegate]window]rootViewController] presentViewController:alert animated:YES completion:nil];
            return nil;
        }];
    }];
}
-(RACCommand *)btn3Command{
    return [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        ViewModel * viewModel = input;
        @weakify(viewModel)
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            @strongify(viewModel)
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@",viewModel.tip,viewModel.name,viewModel.classs,viewModel.physical,viewModel.phone,viewModel.numb] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"取消"];
                [subscriber sendCompleted];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"出错" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendError:[NSError errorWithDomain:@"出错！" code:-1 userInfo:nil]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [subscriber sendNext:@"完成"];
                [subscriber sendCompleted];
            }]];
            [[[[[UIApplication sharedApplication]delegate]window]rootViewController] presentViewController:alert animated:YES completion:nil];
            return nil;
        }];
    }];
}

//-(RACCommand *)topHeaderBtnCommand{
//    return [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
//        ViewModel * viewModel = input;
//        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//            [subscriber sendNext:nil];
//            [subscriber sendCompleted];
//            return nil;
//        }];
//    }];
//}

@end
